﻿using System.Xml.Linq;
using Maple.Weixin.MP.Helpers;

namespace Maple.Weixin.MP.Entities.Messages
{
    public sealed class ResponseMessageMusic : ResponseMessageBase
    {
        internal ResponseMessageMusic(string thumbMediaId, bool encrypt) : base(encrypt) {
            this.ThumbMediaId = thumbMediaId;
        }

        internal ResponseMessageMusic(string thumbMediaId) : this(thumbMediaId, false) {}

        public override ResponseMessageType MessageType
        {
            get { return ResponseMessageType.Music; }
        }

        private string title;
        private string description;
        private string musicUrl;
        private string hqMusicUrl;
        private string thumbMediaId;

        public string Title {
            get { return title ?? ""; }
            set { title = value; }
        }

        public string Description {
            get { return description ?? ""; }
            set { description = value; }
        }

        public string MusicUrl {
            get { return musicUrl ?? ""; }
            set { musicUrl = value; }
        }

        public string HQMusicUrl {
            get { return hqMusicUrl ?? ""; }
            set { hqMusicUrl = value; }
        }

        public string ThumbMediaId {
            get { return thumbMediaId ?? ""; }
            private set { thumbMediaId = value; }
        }

        public override XDocument ToXDocumentBase()
        {
            var document = new XDocument(
                new XElement("xml",
                             new XElement("ToUserName", new XCData(ToUserName)),
                             new XElement("FromUserName", new XCData(FromUserName)),
                             new XElement("CreateTime", WeixinHelper.GetWeixinDateTime(CreateTime)),
                             new XElement("MsgType", new XCData(MessageType.ToString().ToLower())),
                             new XElement("Music", 
                                 new XElement("Title", new XCData(Title)),
                                 new XElement("Description", new XCData(Description)),
                                 new XElement("MusicUrl", new XCData(MusicUrl)),
                                 new XElement("HQMusicUrl", new XCData(HQMusicUrl)),
                                 new XElement("ThumbMediaId", new XCData(ThumbMediaId)))
                    ));
            return document;
        }
    }
}
